package java44th.group.service.admin.collect;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java44th.group.bean.common.BasePageInfo;
import java44th.group.bean.common.CommonData;
import java44th.group.bean.po.MarketCollect;
import java44th.group.bean.po.MarketCollectExample;
import java44th.group.mapper.MarketCollectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * @ProjectName project-second
 * @Descriptiom TODO
 * @Aurhor: 蔡文强
 * @Since: 2022/10/12 20:07
 */
@Service
public class CollectServiceImpl implements CollectService {

    @Autowired
    MarketCollectMapper marketCollectMapper;

    @Override
    public CommonData<MarketCollect> list(BasePageInfo basePageInfo, Integer userId, Integer valueId) {

        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());

        MarketCollectExample example = new MarketCollectExample();
        example.setOrderByClause(basePageInfo.getSort() + " " + basePageInfo.getOrder());
        MarketCollectExample.Criteria criteria = example.createCriteria();
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (valueId != null) {
            criteria.andValueIdEqualTo(valueId);
        }
        List<MarketCollect> list = marketCollectMapper.selectByExample(example);

        PageInfo<MarketCollect> marketCollectPageInfo = new PageInfo<>(list);

        return CommonData.data(marketCollectPageInfo);
    }
}
